<?php

namespace app\index\controller;

use app\common\controller\Frontend;

class Zaixian extends Frontend
{

    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';
    protected $layout = '';

    public function index()
    {
        return $this->view->fetch();
    }
	public function zaixain(){
		header('Content-Type: text/html; charset=utf-8');

		$cid=input('cid');
		$type=input('type');
		 
		$case=db('cases')->find($cid);
		$case['affair']=db('affair')->find($case['affair_id']);
		switch($type){
			case 'que':
				$que=json_decode($case['quejson']);
				$questr="";
				foreach($que as $k=>$v){
					
					$questr.="问：".$v->que."<br/>";
					$questr.="答：".$v->answer."<br/><br/>";
				}
				$users=db('user')->field('mobile')->find($case['user_id']);
				 
				$case['sqrjson']=json_decode($case['sqrjson'],true);
				$birth= strlen($case['sqrjson']['cardno'])==15?('19'.substr($case['sqrjson']['cardno'],6,6)):substr($case['sqrjson']['cardno'],6,8);
				$case['sqrjson']['birth']=substr($birth,0,4).'年'.substr($birth,4,2).'月'.substr($birth,6,2).'日';
				$case['sqrjson']['sex']=  substr($case['sqrjson']['cardno'],(strlen($case['sqrjson']['cardno']))==15?-2:-1)%2?'男':'女';
				$sqrj="{$case['sqrjson']['name']}，{$case['sqrjson']['sex']}，{$case['sqrjson']['birth']}出生，住址：{$case['sqrjson']['addr']}，公民身份证号码：{$case['sqrjson']['cardno']}，联系电话：{$users['mobile']}。";
				$this->assign('caseque',$questr);
				$this->assign('casesqr',$sqrj);
				$this->assign('caseno',$case['caseno']);
				$this->assign('casetime',date('Y-m-d'));
				  
			break;
			
			case 'gaozhi':
				$this->assign('time',date('Y-m-d'));
			break;
			case 'shenqing':
				$users=db('user')->field('mobile')->find($case['user_id']);
				$case['sqrjson']=json_decode($case['sqrjson'],true);
				$birth= strlen($case['sqrjson']['cardno'])==15?('19'.substr($case['sqrjson']['cardno'],6,6)):substr($case['sqrjson']['cardno'],6,8);
				$case['sqrjson']['birth']=substr($birth,0,4).'年'.substr($birth,4,2).'月'.substr($birth,6,2).'日';
				$case['sqrjson']['sex']=  substr($case['sqrjson']['cardno'],(strlen($case['sqrjson']['cardno']))==15?-2:-1)%2?'男':'女';
				$sqrj="{$case['sqrjson']['name']}，{$case['sqrjson']['sex']}，{$case['sqrjson']['birth']}出生，住址：{$case['sqrjson']['addr']}，公民身份证号码：{$case['sqrjson']['cardno']}，联系电话：{$users['mobile']}。";
				$lq=json_decode($case['lqjson'],true);
				$case['lq']='';
				$i=0;
				foreach($lq as $k=>$v){
					$i++;
					$case['lq'].=$v;
					if($i<(count($lq))){
						$case['lq'].=',';
					}
				}
				$files=json_decode($case['filesjson'],true);
				
				$case['files']="";
				$i=0;
				foreach($files as $k=>$v){
					if(isset($v['flist'])){
						$i++;
						$case['files'].=$i."、".$v['name']."(".count($v['flist']).");<br/>";
					}
					
				}
				 
				$this->assign('case',$case);
				$this->assign('casesqr',$sqrj);
				$this->assign('casetime',date('Y-m-d'));
			break;
			case 'heyan':
				$users=db('user')->field('mobile')->find($case['user_id']);
				$case['sqrjson']=json_decode($case['sqrjson'],true);
				$birth= strlen($case['sqrjson']['cardno'])==15?('19'.substr($case['sqrjson']['cardno'],6,6)):substr($case['sqrjson']['cardno'],6,8);
				$case['sqrjson']['birth']=substr($birth,0,4).'年'.substr($birth,4,2).'月'.substr($birth,6,2).'日';
				$case['sqrjson']['sex']=  substr($case['sqrjson']['cardno'],(strlen($case['sqrjson']['cardno']))==15?-2:-1)%2?'男':'女';
				$case['bak_image']=$this->request->domain().'/'.$case['bak_image'];
				$this->assign('case',$case); 
			break;
			case 'shouli':
				$users=db('user')->field('mobile')->find($case['user_id']);
				$case['sqrjson']=json_decode($case['sqrjson'],true);
				$birth= strlen($case['sqrjson']['cardno'])==15?('19'.substr($case['sqrjson']['cardno'],6,6)):substr($case['sqrjson']['cardno'],6,8);
				$case['sqrjson']['birth']=substr($birth,0,4).'年'.substr($birth,4,2).'月'.substr($birth,6,2).'日';
				$case['sqrjson']['sex']=  substr($case['sqrjson']['cardno'],(strlen($case['sqrjson']['cardno']))==15?-2:-1)%2?'男':'女';
				$lq=json_decode($case['lqjson'],true);
				$case['lq']='';
				$i=0;
				foreach($lq as $k=>$v){
					$i++;
					$case['lq'].=$v;
					if($i<(count($lq))){
						$case['lq'].=',';
					}
				}
				$files=json_decode($case['filesjson'],true);
				
				$case['files']="";
				$i=0;
				foreach($files as $k=>$v){
					if(isset($v['flist'])){
						$i++;
						$case['files'].=$i."、".$v['name']."(".count($v['flist']).");<br/>";
					}
					
				}
				 $ziqu=config('site')['ziqu'];
				$this->assign('caseno',$case['caseno']);
				$this->assign('case',$case);
				$this->assign('ziqu',$ziqu);
				$this->assign('users',$users);
				 
				$this->assign('casetime',date('Y-m-d')); 
			break;
			default:
				$que=json_decode($case['quejson']);
				$questr="";
				foreach($que as $k=>$v){
					
					$questr.="问：".$v->que."<br/>";
					$questr.="答：".$v->answer."<br/><br/>";
				}
				$users=db('user')->field('mobile')->find($case['user_id']);
				 
				$case['sqrjson']=json_decode($case['sqrjson'],true);
				$birth= strlen($case['sqrjson']['cardno'])==15?('19'.substr($case['sqrjson']['cardno'],6,6)):substr($case['sqrjson']['cardno'],6,8);
				$case['sqrjson']['birth']=substr($birth,0,4).'年'.substr($birth,4,2).'月'.substr($birth,6,2).'日';
				$case['sqrjson']['sex']=  substr($case['sqrjson']['cardno'],(strlen($case['sqrjson']['cardno']))==15?-2:-1)%2?'男':'女';
				$sqrj="{$case['sqrjson']['name']}，{$case['sqrjson']['sex']}，{$case['sqrjson']['birth']}出生，住址：{$case['sqrjson']['addr']}，公民身份证号码：{$case['sqrjson']['cardno']}，联系电话：{$users['mobile']}。";
				$this->assign('caseque',$questr);
				$this->assign('casesqr',$sqrj);
				$this->assign('caseno',$case['caseno']);
				$this->assign('casetime',date('Y-m-d'));
				 return $this->view->fetch('que');
			break;
		}
		return $this->view->fetch($type);
	}
	public function qianming(){
		return $this->view->fetch();
	}
	public function zuhe(){
		header('Content-Type: text/html; charset=utf-8');

		$cid=input('cid');
		$type=input('type');
	 
		$case=db('cases')->find($cid);
		$case['affair']=db('affair')->find($case['affair_id']);
		
		$que=json_decode($case['quejson']);
		$questr="";
		foreach($que as $k=>$v){
			$questr.="问：".$v->que."<br/>";
			$questr.="答：".$v->answer."<br/><br/>";
		}
		
		$case['sqrjson']=json_decode($case['sqrjson'],true);
		$birth= strlen($case['sqrjson']['cardno'])==15?('19'.substr($case['sqrjson']['cardno'],6,6)):substr($case['sqrjson']['cardno'],6,8);
		$case['sqrjson']['birth']=substr($birth,0,4).'年'.substr($birth,4,2).'月'.substr($birth,6,2).'日';
		$case['sqrjson']['sex']=  substr($case['sqrjson']['cardno'],(strlen($case['sqrjson']['cardno']))==15?-2:-1)%2?'男':'女';
		$users=db('user')->field('mobile')->find($case['user_id']);
		
		$sqrj="{$case['sqrjson']['name']}，{$case['sqrjson']['sex']}，{$case['sqrjson']['birth']}出生，住址：{$case['sqrjson']['addr']}，公民身份证号码：{$case['sqrjson']['cardno']}，联系电话：{$users['mobile']}。";
		
		
		$lq=json_decode($case['lqjson'],true);
		$case['lq']='';
		$i=0;
		foreach($lq as $k=>$v){
			$i++;
			$case['lq'].=$v;
			if($i<(count($lq))){
				$case['lq'].=',';
			}
		}
		
		$files=json_decode($case['filesjson'],true);
		$case['files']="";
		$i=0;
		foreach($files as $k=>$v){
			if(isset($v['flist'])){
				$i++;
				$case['files'].=$i."、".$v['name']."(".count($v['flist']).");<br/>";
			}
			
		}
		
		$case['bak_image']=$this->request->domain().'/'.$case['bak_image'];
		$ziqu=config('site')['ziqu'];
		
		$this->assign('casesqr',$sqrj);
		$this->assign('caseque',$questr);
		$this->assign('caseno',$case['caseno']);
		$this->assign('casetime',date('Y-m-d'));
		$this->assign('case',$case); 
		$this->assign('ziqu',$ziqu);
		$this->assign('users',$users); 
		 
		return $this->view->fetch();
	}
}
